package dome4;

import dome1.Student;

import java.util.Arrays;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description: String类代码测试
 * User: 王圆豪
 * Date: 2024-06-28
 * Time: 16:08
 */
public class Test {
    public static void main17(String[] args) {
        String s = " a b c %$^";
//        System.out.println(s.trim());
        System.out.println(s.toUpperCase());
    }
    public static void main16(String[] args) {
        String s = "abcdefghi";
        System.out.println(s.substring(3, 6));
    }
    public static void main15(String[] args) {
        String s1 = "he&llo=&wor=ld-=wel-come";
        System.out.println(Arrays.toString(s1.split("=&|-=")));
    }
    public static void main14(String[] args) {
        String s = "abcdecfg";
        String s1 = s.replaceFirst("c", "cc");
        System.out.println(s1);
    }
    public static void main13(String[] args) {
        String s = "abcdefg";
        String s1 = s.replaceAll("c", "cc");
        System.out.println(s1);
    }
    public static void main12(String[] args) {
        int year = 2024;
        int month = 6;
        int day = 29;
        String s = String.format("%02d-%02d-%02d", year, month, day);
        System.out.println(s);
    }
    public static void main11(String[] args) {
        String s = "hello";
        String s1 = s.toUpperCase();
        System.out.println(s1);
        String s2 = s1.toLowerCase();
        System.out.println(s2);
    }
    public static void main10(String[] args) {
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student("wyh", 12));
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
    }
    public static void main9(String[] args) {
        String s = "abcdef";
        int pos = s.lastIndexOf("cd", 1);
        System.out.println(pos);
    }
    public static void main8(String[] args) {
        String s = "abcdef";
        int pos = s.indexOf("bc", 2);
        System.out.println(pos);
    }
    public static void main7(String[] args) {
        String s = "abcdef";
        char ch = s.charAt(2);
        System.out.println(ch);
    }
    public static void main6(String[] args) {
        String s1 = "abc";
        String s2 = "ABC";
        System.out.println(s1.compareToIgnoreCase(s2));
    }
    public static void main5(String[] args) {
        String s1 = "abc";
        String s2 = "acc";
        System.out.println(s1.compareTo(s2));
    }
    public static void main4(String[] args) {
        String s1 = "abc";
        String s2 = "def";
        String s3 = new String("abc");
        System.out.println(s1.equals(s2));//false
        System.out.println(s1.equals(s3));//true
    }
    public static void main3(String[] args) {
        String str = "Hello";
        int hashCode = System.identityHashCode(str); // 获取字符串对象的哈希码
        String address = Integer.toHexString(hashCode); // 将哈希码转换为十六进制字符串
        System.out.println("Address of the string: " + hashCode);
    }
    public static void main2(String[] args) {
        String s1 = "abc";
        String s2 = new String("abc");
        String s3 = s1;
        System.out.println(s1 == s2);//false
        System.out.println(s1 == s3);//ture
    }
    public static void main(String[] args) {
        long start = System.currentTimeMillis();//获得程序开始的时间
        String s1 = "";
        for (int i = 0; i < 10000; i++) {
            s1 += i;
        }
        long end = System.currentTimeMillis();//获得程序结束的时间
        System.out.println(end -  start);//打印开始与结束这段代码的运行时间，单位为毫秒。

        start = System.currentTimeMillis();//获得程序开始的时间
        StringBuffer sbf = new StringBuffer("");
        for (int i = 0; i < 10000; i++) {
            sbf.append(i);
        }
        end = System.currentTimeMillis();//获得程序结束的时间
        System.out.println(end -  start);//打印开始与结束这段代码的运行时间，单位为毫秒。

        start = System.currentTimeMillis();//获得程序开始的时间
        StringBuilder sbd = new StringBuilder();
        for (int i = 0; i < 10000; i++) {
            sbd.append(i);
        }
        end = System.currentTimeMillis();//获得程序结束的时间
        System.out.println(end -  start);//打印开始与结束这段代码的运行时间，单位为毫秒。
    }
}
